
package eti.vilas;

public class Abast
{

   private Integer id;

   private String placa;
   private Integer cnh;

   private String data;
   private float vrLitro;
   private float vrTotal;
   private Integer kmStart;
   private Integer kmEnd;
   private Integer litros;
   private String combustivel;

   public Integer getId()
   {
      return id;
   }

   public void setId(Integer id)
   {
      this.id = id;
   }

   public String getPlaca()
   {
      return placa;
   }

   public void setPlaca(String placa)
   {
      this.placa = placa;
   }

   public Integer getCnh()
   {
      return cnh;
   }

   public void setCnh(Integer cnh)
   {
      this.cnh = cnh;
   }

   public String getData()
   {
      return data;
   }

   public void setData(String data)
   {
      this.data = data;
   }

   public float getVrLitro()
   {
      return vrLitro;
   }

   public void setVrLitro(float vrLitro)
   {
      this.vrLitro = vrLitro;
   }

   public float getVrTotal()
   {
      return vrTotal;
   }

   public void setVrTotal(float vrTotal)
   {
      this.vrTotal = vrTotal;
   }

   public Integer getKmStart()
   {
      return kmStart;
   }

   public void setKmStart(Integer kmStart)
   {
      this.kmStart = kmStart;
   }

   public Integer getKmEnd()
   {
      return kmEnd;
   }

   public void setKmEnd(Integer kmEnd)
   {
      this.kmEnd = kmEnd;
   }

   public Integer getLitros()
   {
      return litros;
   }

   public void setLitros(Integer litros)
   {
      this.litros = litros;
   }

   public String getCombustivel()
   {
      return combustivel;
   }

   public void setCombustivel(String combustivel)
   {
      this.combustivel = combustivel;
   }

   @Override
   public String toString()
   {
      return "Abast [id=" + id + ", placa=" + placa + ", cnh=" + cnh
            + ", data=" + data + ", vrLitro=" + vrLitro + ", vrTotal="
            + vrTotal + ", kmStart=" + kmStart + ", kmEnd=" + kmEnd
            + ", litros=" + litros + ", combustivel=" + combustivel + "]";
   }

   public String sqlInsert()
   {
      return String
               .format(
                  "INSERT INTO abastecimento ( placa, cnh, data, vr_litro, vr_total, km_start, km_end, litros, combustivel ) VALUES ( '%s','%s',DATETIME('NOW'),'%s','%s','%s','%s','%s','%s')",
                  placa, cnh, vrLitro, vrTotal, kmStart, kmEnd, litros, combustivel);
   }

   public String sqlUpdate()
   {
      return String
         .format("UPDATE abastecimento SET placa='%s',cnh='%s',data='%s',vr_litro='%s',vr_total='%s',km_start='%s',km_end='%s',litros='%s',combustivel='%s' WHERE rowid='" + id + "'",
            placa, cnh, data, vrLitro, vrTotal, kmStart, kmEnd, litros, combustivel);
   }

   public String sqlDelete()
   {
      return "DELETE FROM abastecimento WHERE rowid='" + id + "'";
   }

   public static String sqlSelect()
   {
      // return
      // "select A.combustivel,C.nome,A.date,A.km_start,A.km_end,(A.km_end - A.km_start) Km,A.litros, ((A.km_end - A.km_start ) / A.litros ) 'Km/L' from abastecimento A join condutor C on C.cnh=A.cnh";
      return "select A.rowid,A.* from abastecimento A join condutor C on C.cnh=A.cnh order by A.data";
   }

   public static String sqlSelectByConsumo()
   {
      return "select C.nome,A.combustivel,A.data,A.km_start,A.km_end,(A.km_end - A.km_start) Km,A.litros, ((A.km_end - A.km_start ) / A.litros ) 'Km/L' from abastecimento A left join condutor C on C.cnh=A.cnh left join veiculo V on V.placa=A.placa --order by A.combustivel";
   }

   public static String sqlSelectLast()
   {
      return "select A.rowid,A.* from abastecimento A where A.rowid = ( select max(rowid) from abastecimento )";
   }

}
